[ai_vars]
	north_dest="if([me.loc.x,me.loc.y]=[4,3],"loc(17,8)","if([me.loc.x,me.loc.y]=[17,8],"loc(4,3)",self)")"
[/ai_vars]
formula="move(me.loc, new_loc)"
where 	new_loc=choose(unit_moves(me.loc), 'moveto', -distance_between(moveto, north_dest))



[function]
name=top_dest
inputs="ai*, unit"
formula="switch(unit.loc, loc(4,3), loc(17,8), loc(17,8), loc(4,3), unit.loc)"
[/function]

[function]
name=left_dest
inputs="ai*, unit"
formula="switch(unit.loc, loc(2,18), loc(3,5), loc(3,5), loc(2,18), unit.loc)"
[/function]



1	my_units
we have a list of our units

2	head(above), filter(above, head(above))
we get the first unit, and the tail

3	get_unit_loc(above)
we get the loc of the unit

4	shortest_path(above, "switch(2.id, this, north_dest(2), that, west_dest(2))")
	where 	this="'north_drake'"
			that="'west_drake'"
we get the list of hexes on the shortest path to destination

5	move_partial(3,head(above))
we get our unit to move towards the destination

"move_partial(first_unit.loc, head(shortest_path(first_unit.loc, switch(first_unit.id, this, top_dest(first_unit), that, left_dest(first_unit)))))
where first_unit="head(filter(my_units, movement_left>0))", this="'Top_drake'", that="'Left_drake'""

move="move_partial(first_unit.loc, head(shortest_path(first_unit.loc, switch(first_unit.id, this, top_dest(first_unit), that, left_dest(first_unit)))))
where first_unit=head(filter(my_units, self.movement_left>0)), this='Top_drake', that='Left_drake'"

move_partial(loc(18,8), head(shortest_path(loc(18,8),loc(13,10)))) 

switch(first_unit.id, this, top_dest(first_unit), that, left_dest(first_unit))

move_partial(first_unit.loc, head(shortest_path(first_unit.loc, switch(first_unit.id, 'Top_Drake', top_dest(first_unit), 'Left_Drake', left_dest(first_unit)))))
				where first_unit=head(filter(my_units, self.movement_left>0))

[function]
	name=current_dest
	inputs="unit"
	formula="switch(unit.loc, loc(4,3), loc(17,8), loc(17,8), loc(4,3), loc(2,18), loc(3,5), loc(3,5), loc(2,18), unit.loc)"
[/function]				
move="if(first_unit!=[], move_partial(first_unit.loc, head(shortest_path(first_unit.loc, current_dest(first_unit)))), [])
				where first_unit=if(filter(my_units, movement_left>0)=[], [], head(filter(my_units, movement_left>0)))"

[function]
name=move_x_y
inputs="ai*, loc_pair"
formula="move(loc_pair[0],loc_pair[1])"
[/function]

[function]
name=get_unit_loc
inputs="ai*, unit"
formula="unit.loc"
[/function]

[function]
name=tail
inputs="ai*,a_list"
formula="filter(a_list,self!=head(a_list))"
[/function]

[function]
name=recur_path
inputs="ai*,path"
formula="if(head(path)=[], [], recur_path(ai,tail(path)))"
[/function]


